﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>速度最快的反序列化</h3>
    <p>
        一般情况下Newtonsoft.Json已经很快了。
        我们经常需要把实体类反序列化为字符串,但是如果为了加快效率就可以采用以下方式进行反序列化。
        实体类中只能含有由以下类型组成的字段和属性。<br />
        SByte,Byte,Int16,UInt16,Int32,UInt32,Int64,UInt64,Boolean,<br />
        Char,Decimal,Double,Single,DateTime,DateTimeOffset，<br />
        SByte?,Byte?,Int16?,UInt16?,Int32?,UInt32?,Int64?,UInt64?,Boolean?,<br />
        Char?,Decimal?,Double?,Single?,DateTime?,DateTimeOffset?<br /><br />
        <pre class="brush:csharp;">
            public class User
            {
                public int id {get;set;}
                public string name {get;set;}
                public string pwd {get;set;}
            }
        </pre>
        <pre class="brush:csharp;">
            using NFinal.Json;
            public class IndexController : BaseController
            {
                public Index()
                {
                    User user=new User();
                    user.id=1;
                    user.name="Lucas";
                    user.pwd="123456";
                    //直接输出Json
                    JsonHelper.GetJson(user,this,DateTimeFormat.Local);
                    //简单的写法如下
                    string str=GetModelJson(user);
                    this.Write(str);
                }
            }
        </pre>
    </p>
</body>
</html>